const { v4 } = require("uuid");
const PublicModel = require('../public.model');

/**
 * 消息业务服务
 */
class MessageBusinessService {
    publicModel = new PublicModel();

    /**
     * 设置菜单食物操作消息
     * @param {*} param0 
     * @returns 
     */
    async setMenuFoodAction(content, { uid, gid, type }) {
        try {
            const action_type = type || 0;
            const id = v4();
            const SQL = `
                INSERT INTO
                    message_menu_food_actions (
                    id, content, family_group_id, action_type, create_time, create_user 
                    ) 
                VALUE 
                    ('${id}', '${content}', '${gid}', ${action_type}, '${this.publicModel.time}', '${uid}')
            `;
            const result = await this.publicModel.query(SQL);
            if (result.code === 200 && result.results.affectedRows > 0) {
                return true;
            }
            return false;
        } catch (error) {
            console.log(error);
            return false;
        }
    }
}

module.exports = new MessageBusinessService();